<?php
/**
 * Created by PhpStorm.
 * User: wangwenfan
 * Date: 2018/9/12
 * Time: 16:33.
 */

namespace App\Admin\Controllers;

use App\Models\Base\ChatRobot;
use App\Models\Base\ServerList;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;

class ChatRobotController
{
    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('game.player_related'));
            $content->description(trans('game.chat_log'));

            $content->body($this->grid());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(ChatRobot::class, function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->id();
            $grid->player_id('ID');
            $grid->name(trans('game.role_name'));
            $grid->serverName()->name(trans('game.server_name'));
            $grid->content(trans('game.content'));
            $grid->number(trans('game.repeat_number'));
            $grid->created_at(trans('game.stat_time'));
            $grid->disableCreateButton();
            $grid->disableExport();
            $grid->disableActions();
            $grid->filter(function ($filter) {
                $filter->disableIdFilter();
                // 去掉默认的id过滤器
                $filter->equal('server_id', trans('game.server_name'))->select(ServerList::all()->pluck('name', 'server_id'));
                $filter->like('name', trans('game.role_name'));
            });
        });
    }
}
